package com.ephuizi.excel;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

/**
 * 导出的excel字段
 * 
 * @author ephuizi@gmail.com
 *
 */
public class ExcelConstantField {

	public static final String orderId = "订单号";
	public static final String orderCreateTime = "订单生成时间";
	public static final String orderType = "模型类型";
	public static final String orderZodiac = "生肖";
	public static final String orderContent = "订单内容";
	public static final String moduleImg = "模型图片";
	public static final String moduleStl = "模型stl";
	public static final String moduleGcode = "模型gcode";
	public static final String fontName = "字体";
	public static final String color = "颜色";
	public static final String orderAdress = "地址";
	public static final String receiverName = "收货人";
	public static final String receiverMobile = "手机号码";
	public static final String productionBatch = "打印批次";
	public static final String printStatus = "打印与否";
	public static final String printer = "打印者";
	public static final String courierNumber = "快递单号";

	/*
	 * 返回带顺序的field名称
	 */
	public static String[] fieldNameToArrayBySort() {
		return new String[] { "orderId", "orderCreateTime", "orderType", "orderZodiac", "orderContent"//
				, "moduleImg", "moduleStl", "moduleGcode", "fontName", "color"//
				, "orderAdress", "receiverName", "receiverMobile", "productionBatch", "printStatus"//
				, "printer", "courierNumber" };
	}

	/**
	 * 返回字段占的列宽数组
	 * 
	 * @return
	 */
	public static int[] fieldWidthArray() {
		return new int[] { 5000, 5000, 2500, 2500, 5000// 订单内容
				, 3000, 3000, 3000, 2500, 2500// 颜色
				, 10000, 3000, 5000, 5000, 2500// 打印与否
				, 5000, 5000// 快递单号
		};
	}

	/**
	 * 验证代码ExcelConstantField和RecordRow字段对应关系是否正确
	 * 
	 * @return
	 */
	public static boolean fieldArrayVerify() {
		String[] fieldNames = fieldNameToArrayBySort();
		Set<String> set = new HashSet<>();
		for (int i = 0; i < fieldNames.length; i++) {
			set.add(fieldNames[i]);
		}

		boolean verify = true;
		Field[] ecfFields = ExcelConstantField.class.getFields();
		for (int i = 0; i < ecfFields.length; i++) {
			if (!set.contains(ecfFields[i].getName())) {
				// System.out.println(ecfFields[i].getName());
				verify = false;
				break;
			}
		}
		if (verify) {
			Field[] rrFields = RecordRow.class.getFields();
			for (int i = 0; i < rrFields.length; i++) {
				if (!set.contains(rrFields[i].getName())) {
					// System.out.println(rrFields[i].getName());
					verify = false;
					break;
				}
			}
		}
		return verify;
	}
}
